package com.sp.homework;

import java.io.*;

/**
 * 1. 在判断"d:\\development\\code\\IO_Test\\news\\"下是否有文件夹mytemp, 如果没有就创建mytemp
 * 2. 在"d:\\development\\code\\IO_Test\\news\\mytemp"目录下, 创建文件hello.txt
 * 3. 如果hello.txt已经存在, 提示该文件已经存在, 就不要重复创建了
 * 4. 并且在hello.txt文件中, 写入"hello, world"
 */
public class Homework01 {
    public static void main(String[] args) throws IOException {
        String path = "d:\\development\\code\\IO_Test\\news\\";
        File file = new File(path + "mytemp");

        if (!(file.exists() && file.isDirectory())){
            file.mkdirs();
            System.out.println("mytemp文件夹创建成功");
        } else {
            System.out.println("mytemp文件夹已存在");
        }

        File file1 = new File(path + "mytemp", "hello.txt");
        if (file1.exists() && file1.isFile()){
            System.out.println("hello.txt文件已存在");
        } else {
            file1.createNewFile();
            System.out.println("hello.txt创建成功");
        }

        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("d:\\development\\code\\IO_Test\\news\\mytemp\\hello.txt"));
        bufferedWriter.write("hello, world");
        System.out.println("写入成功");
        bufferedWriter.close();

    }
}
